<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net 
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : order.manage.php   FILE_PATH : E:\web\mulitishop\system\order.manage.php
 * 订单管理
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 
 * @package 
 * @subpackage 
 * @version Tue Nov 13 10:16:38 CST 2007
 */

require_once("../global.inc.php");

class SysProductOrderManage extends SystemFrameWork{
	/**
	 * 订单对象
	 *
	 * @var obj
	 */
	var $obj_product_order;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $obj_validate;
	/**
	 * 会员对象
	 *
	 * @var obj
	 */
	var $obj_member;
	
	function main(){
		/**
		 * 创建订单对象
		 */
		if (!is_object($this->obj_product_order)){
			require_once("order.class.php");
			$this->obj_product_order = new ProductOrderClass();
		}		
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->obj_validate)){
			require_once("commonvalidate.class.php");
			$this->obj_validate = new CommonValidate();
		}
		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("system");

		/**
		 * 语言包
		 */
		$this->getlang("product");
		
		switch ($this->_input['action']){
			case "view":
				$this->_view_product_order();
				break;
			case "del":
				$this->_del_product_order();
				break;
			default:
				$this->_list_product_order();
				break;
		}
		
	}
	
	/**
	 * 订单列表
	 */
	function _list_product_order(){
		/**
		 * 初始化分页类
		 */
		require_once("commonpage.class.php");
		$obj_page = new CommonPage();
		/**
		 * 实例化用户类
		 */
		if (!is_object($this->obj_member)){
			require_once("member.class.php");
			$this->obj_member = new MemberClass();
		}

		/**
		 * 获得参数
		 */
		$obj_condition[sell_type] = $this->_input['search_sell_type'];
		if ($this->_input['search_sp_state'] != ""){
			$obj_condition[state] = $this->_input['search_sp_state'];
		}else {
			$obj_condition[state] = array('0'=>'0','1'=>'1','2'=>'2','3'=>'3');
		}
		$obj_condition[comment] = $this->_input['search_comment'];
		/**
		 * 取得订单列表
		 */
		$obj_page->pagebarnum(10);
		$product_order_array = $this->obj_product_order->getProductOrderList($obj_condition, $obj_page);
		if(is_array($product_order_array)){
			foreach ($product_order_array as $key => $value){
				/**
				 * 取卖家资料
				 */
				$condition['id'] = $value['seller_id'];
				$member_info = $this->obj_member->getMemberInfo($condition);
				unset($condition);
				$product_order_array[$key]['seller_name'] = $member_info['login_name'];
				/**
				 * 取买家资料
				 */
				$condition['id'] = $value['buyer_id'];
				$member_info = $this->obj_member->getMemberInfo($condition);
				unset($condition);
				$product_order_array[$key]['buyer_name'] = $member_info['login_name'];
				/*判断双方评价*/
				if ($value['sole_have_comment'] == 1 && $value['buy_have_comment'] == 0){
					$product_order_array[$key]['comment'] = $this->_lang['langOrderCommentOne'];
				}elseif ($value['sole_have_comment'] == 0 && $value['buy_have_comment'] == 1){
					$product_order_array[$key]['comment'] = $this->_lang['langOrderCommentTwo'];
				}elseif ($value['sole_have_comment'] == 1 && $value['buy_have_comment'] == 1){
					$product_order_array[$key]['comment'] = $this->_lang['langOrderCommentThree'];
				}elseif ($value['sole_have_comment'] == 0 && $value['buy_have_comment'] == 0){
					$product_order_array[$key]['comment'] = $this->_lang['langOrderCommentFour'];
				}
			}
		}
		$page_list = $obj_page->show(1);
		
		/**
		 * 更新40天以前的订单评价
		 */
		$this->obj_product_order->orderAutoComment();
		/**
		 * 页面输出
		 */
		$this->output("p_sell_type", $this->_b_config['p_sell_type']);/*商品交易类型，一口价等*/
		$this->output("sp_state", $this->_b_config['sp_state']);/*商品交易状态*/
		$this->output("page_list", $page_list);
		$this->output("product_order_array", $product_order_array);
		$this->showpage('sys_product_order.manage');
	}
	
	/**
	 * 删除订单
	 */
	function _del_product_order(){
		$this->_input['txtDel'] = 1;
		$this->obj_product_order->updateProductDelState($this->_input);
		echo 'ok';
		exit;
	}
	
	/**
	 * 查看订单信息
	 */
	function _view_product_order(){
		/**
		 * 实例化用户类
		 */
		if (!is_object($this->obj_member)){
			require_once("member.class.php");
			$this->obj_member = new MemberClass();
		}
		
		$sp_id = $this->_input['sp_id'];
		$order_array = $this->obj_product_order->getOneOrder($sp_id);
		/**
		 * 取卖家资料
		 */
		$condition['id'] = $order_array['seller_id'];
		$member_info = $this->obj_member->getMemberInfo($condition);
		unset($condition);
		$order_array['seller_name'] = $member_info['login_name'];
		/**
		 * 取买家资料
		 */
		$condition['id'] = $order_array['buyer_id'];
		$member_info = $this->obj_member->getMemberInfo($condition);
		unset($condition);
		$order_array['buyer_name'] = $member_info['login_name'];
		/**
		 * 页面输出
		 */
		$this->output("p_sell_type", $this->_b_config['p_sell_type']);/*商品交易类型，一口价等*/
		$this->output("sp_state", $this->_b_config['sp_state']);/*商品交易状态*/
		$this->output('order_array',$order_array);
		$this->showpage('sys_product_order.view');
	}
}

$order_manage = new SysProductOrderManage();
$order_manage->main();
unset($order_manage);
?>